<template>
  <div class="workerbox" v-if="this.workerArr.length">
    <p class="title">参照这个菜谱，大家做出{{ workerArr.length }}作品</p>
    <p class="all">全部{{ workerArr.length }}个作品</p>
    <div class="main">
      <template v-for="(item, index) in workerArr" >
        <div class="box" v-if="index < 4" :key="index">
          <div class="imgb">
            <img :src="item.img" alt="" class="worker" />
            <div class="fugai"></div>
          </div>
          <p class="time">{{ item.pushtime }}</p>
          <p class="text">{{ item.tip }}</p>
          <div class="user">
            <img :src="item.touxiang" alt="" class="uimg" />
            <span class="uname">{{ item.username }}</span>
          </div>
        </div>
      </template>
    </div>
    <p class="upwork" @click="fupload()">上传你做的{{ menuTitle }}</p>
  </div>
</template>

<script>
export default {
  data() {
    return {
      workerArr: [],
    };
  },
  props: ["menuTitle", "menuid"],
  mounted() {
    this.$axios("/wxw/wcookopus", {
      params: { cookid: this.menuid },
    }).then((res) => {
      this.workerArr = res.data;
    });
  },
  watch: {
    menuid() {
      this.$axios("/wxw/wcookopus", {
        params: { cookid: this.menuid },
      }).then((res) => {
        this.workerArr = res.data;
      });
    },
  },
  methods:{
    // 上传作品
    fupload(){
      this.$router.push({
        path: `/uploadopus/${this.menuid}`,
      });
    }
  }
};
</script>

<style scoped lang="scss">
.workerbox {
  position: relative;
}
.title {
  font-size: 24px;
  color: #c0ae7d;
  margin-bottom: 20px;
}
.all {
  color: #dd3915;
  font-size: 14px;
  position: absolute;
  top: 5px;
  right: 20px;
  font-weight: bolder;
}
.main {
  display: flex;
  .box {
    font-size: 12px;
    color: #333;
    width: 150px;
    border: 1px solid #eee;
    margin-right: 15px;
    position: relative;
    .imgb {
      cursor: pointer;
      .fugai {
        width: 150px;
        height: 150px;
        position: absolute;
        top: 0;
        left: 0;
        background-color: rgba(200, 200, 200, 0.4);
        display: none;
      }
      .worker {
        width: 150px;
        height: 150px;
      }
      &:hover > .fugai {
        display: block;
      }
    }

    .time {
      margin: 10px;
    }
    .text {
      margin: 10px;
      height: 48px;
      overflow: hidden;
    }
    .user {
      margin: 30px 10px 10px;
      .uimg {
        width: 20px;
        height: 20px;
        border-radius: 50%;
        margin-right: 10px;
      }
      .uname {
        color: red;
      }
    }
  }
}
.upwork {
  display: block;
  margin-top: 30px;
  width: 630px;
  height: 50px;
  line-height: 50px;
  text-align: center;
  background-color: #dd3915;
  color: #fff;
  font-size: 15px;
  cursor: pointer;
}
</style>